package com.pfs.internal.timestamp.utils;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.util.StrutsTypeConverter;

public class DateConverter extends StrutsTypeConverter {
	protected static final Logger logger = Logger.getLogger(DateConverter.class);

	@SuppressWarnings("rawtypes")
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {

		String str = values[0];
		logger.debug("DateConverter: String: " + str);
		try {
			return Formater.str2sqldate(str);
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public String convertToString(Map context, Object o) {
		Date date = (Date) o;
		logger.debug("DateConverter: Date: " + date);
		return Formater.date2str(date);
	}
}
